package com.shoping.web.service;

import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 *
 * @author zengweilong
 * @date 2021/4/9 10:43 AM
 */
@Data
@Service
public class TeacherService implements InitializingBean {

    @Value("${spring.application.name}")
    private String desc;

    @Autowired
    private StudentService studentService;

    private String remark;

    public TeacherService() {
        System.out.println("TeacherService的构造函数被执行啦");
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        System.out.println("调用setDesc方法");
        this.desc = desc;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        System.out.println("调用setRemark方法");
        this.remark = remark;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("调用afterPropertiesSet方法");
        this.desc = "在初始化方法中修改之后的描述信息";
    }

    @PostConstruct
    public void initMethod() {
        System.out.println("调用initMethod方法");
    }

    @Override
    public String toString() {
        System.out.println(studentService.toString());
        StringBuilder builder = new StringBuilder();
        builder.append("[描述：").append(desc);
        builder.append("， 备注：").append(remark).append("]");
        return builder.toString();
    }
}
